﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.ComponentModel.Composition;
using ModularAndPlugin.WebApp.FormComposition;

namespace ModularAndPlugin.WebApp.FormComposition.WebExtensions
{
	public class ComposableWebHandlerFactory : SimpleWebHandlerFactory
	{
		public override IHttpHandler GetHandler(HttpContext context, string requestType, string virtualPath, string path)
		{
			IHttpHandler handler = base.GetHandler(context, requestType, virtualPath, path);

			if (handler != null)
			{
				CompositionBatch batch = new CompositionBatch();
				batch = ComposeWebPartsUtils.BuildUp(batch, handler);
				ContextualCompositionHost.Container.Compose(batch);
			}

			return handler;
		}

	}
}
